<?php
/** ******************************************************************************
 * 
 * This file is under copyright of Zeedler Ztudio. Do not be modified or amended,
 * To study or co-source code. Can be contacted at administrator@zeedler.net.
 * Or visit the information. www.zeedler.com and www.zeedler.net.
 * 
 ********************************************************************************/ 

# before use this class please include globaltools and pathfile.
if (!$rootPath) {
	$root = $_SERVER["DOCUMENT_ROOT"];
	$dir = dirname(__FILE__);
	$dir = str_replace($root, "", $dir);
	$dir = str_replace("install", "", $dir);
	$rootPath = $root.$dir;
	include($rootPath."globaltools.php");
	Ztools::file_replace($rootPath."pathfile.php", "\$rootPath = \"|*|\" -| $rootPath");
	include($rootPath."pathfile.php");
}

class Zinstall {
	/**
	 * Setup New Config. Return Boolean and Another Flag.
	 * If it return 2 Because you must create the DataBase first.
	 * If it return false Because your parameter to connect to database are invalid.
	 * If it return true Because it setup config file successfull.
	 */
	function setup_config($dbhost, $dbuser, $dbpass, $dbname, $charset = "uft8", $prefix = "", $result = 0) {
		if (!$charset) { $charset = "utf8"; }
		if ((!$dbhost) || (!$dbuser) || (!$dbpass) || (!$dbname)) { return false; }
		else {
			$dbhost = trim($dbhost);
			$dbuser = trim($dbuser);
			$dbpass = trim($dbpass);
			$dbname = trim($dbname);
			$connect = Ztools::connectdb($dbhost, $dbuser, $dbpass, $dbname, $charset);
			if ($connect == 2) {
				return 2;
			} elseif (false === $connect) {
				return false;
			} elseif ((false !== $connect) && ($connect != 2)) {
				$edit = "(\"__dbhost__\", \"|*|\"); -| $dbhost";
				$edit .= " <> (\"__dbuser__\", \"|*|\"); -| $dbuser";
				$edit .= " <> (\"__dbpass__\", \"|*|\"); -| $dbpass";
				$edit .= " <> (\"__dbname__\", \"|*|\"); -| $dbname";
				$edit .= " <> (\"__charset__\", \"|*|\"); -| $charset";
				$edit .= " <> (\"__tbprefix__\", \"|*|); -| $prefix\"";
				$ed = Ztools::file_replace(Ztools::rootPath."config.ini.php", $edit, $result);
				if (false === $ed) { return false; }
				else { if ($result != 0) { return $ed; } else { return true; } }
			}
			mysql_close($connect);
		}
	}
}
?>